﻿using Basic.FormRemoteModel;
using Basic.HrRemoteModel.DicItem.Model;
using WeDonekRpc.Helper;

namespace Basic.UserFormService.Calculate.Model
{
    public struct RecordVal
    {
        public object value;

        public DicItem[] dicItem;
        public FormRecordDataType dataType;

        public DataFuncType funcType;

        public Dictionary<string, string> items;
        public override int GetHashCode ()
        {
            if ( this.value == null )
            {
                return -1;
            }
            return this.value.GetHashCode();
        }
        public override bool Equals ( object? obj )
        {
            if ( obj == null )
            {
                return false;
            }
            if ( obj is RecordVal i )
            {
                return i == this;
            }
            else if ( obj is decimal n )
            {
                return this == n;
            }
            else if ( obj is long lon )
            {
                return this == lon;
            }
            else if ( obj is string str )
            {
                return this == str;
            }
            else if ( obj is bool bit )
            {
                return this == bit;
            }
            return false;
        }

        public override string ToString ()
        {
            return this.value?.ToString();
        }
        public static decimal operator + ( RecordVal left, decimal right )
        {
            return Convert.ToDecimal(left.value) + right;
        }
        public static decimal operator + ( decimal left, RecordVal right )
        {
            return Convert.ToDecimal(right.value) + left;
        }
        public static decimal operator - ( RecordVal left, decimal right )
        {
            return Convert.ToDecimal(left.value) - right;
        }
        public static decimal operator - ( decimal left, RecordVal right )
        {
            return left - Convert.ToDecimal(right.value);
        }
        public static decimal operator * ( RecordVal left, decimal right )
        {
            return Convert.ToDecimal(left.value) * right;
        }
        public static decimal operator * ( decimal left, RecordVal right )
        {
            return left * Convert.ToDecimal(right.value);
        }
        public static decimal operator / ( RecordVal left, decimal right )
        {
            return Convert.ToDecimal(left.value) / right;
        }
        public static decimal operator / ( decimal left, RecordVal right )
        {
            return left / Convert.ToDecimal(right.value);
        }
        public static int operator & ( RecordVal left, int right )
        {
            return Convert.ToInt32(left.value) & right;
        }
        public static int operator & ( int left, RecordVal right )
        {
            return left & Convert.ToInt32(right.value);
        }
        public static decimal operator % ( RecordVal left, decimal right )
        {
            return Convert.ToDecimal(left.value) % right;
        }
        public static decimal operator % ( decimal left, RecordVal right )
        {
            return left % Convert.ToDecimal(right.value);
        }
        public static RecordVal operator ++ ( RecordVal num )
        {
            num.value = Convert.ToDecimal(num.value) + 1;
            return num;
        }
        public static RecordVal operator -- ( RecordVal num )
        {
            num.value = Convert.ToDecimal(num.value) - 1;
            return num;
        }
        public static bool operator >= ( RecordVal left, RecordVal right )
        {
            if ( right.dataType == FormRecordDataType.Bool || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            else if ( left.value == null || right.value == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                  right.dataType == FormRecordDataType.Date ||
                  right.dataType == FormRecordDataType.DateTime ||
                  right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) >= Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left.value) >= Convert.ToDecimal(right.value);
        }
        public static bool operator <= ( RecordVal left, RecordVal right )
        {
            if ( right.dataType == FormRecordDataType.Bool || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            else if ( left.value == null || right.value == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                  right.dataType == FormRecordDataType.Date ||
                  right.dataType == FormRecordDataType.DateTime ||
                  right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) <= Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left.value) <= Convert.ToDecimal(right.value);
        }
        public static bool operator > ( RecordVal left, RecordVal right )
        {
            if ( right.dataType == FormRecordDataType.Bool || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            else if ( left.value == null || right.value == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                  right.dataType == FormRecordDataType.Date ||
                  right.dataType == FormRecordDataType.DateTime ||
                  right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) > Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left.value) > Convert.ToDecimal(right.value);
        }
        public static bool operator < ( RecordVal left, RecordVal right )
        {
            if ( right.dataType == FormRecordDataType.Bool || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            else if ( left.value == null || right.value == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                  right.dataType == FormRecordDataType.Date ||
                  right.dataType == FormRecordDataType.DateTime ||
                  right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) < Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left.value) < Convert.ToDecimal(right.value);
        }
        #region decimal
        public static bool operator == ( RecordVal left, decimal right )
        {
            if ( left.dataType != FormRecordDataType.Number )
            {
                return false;
            }
            return Convert.ToDecimal(left.value) == right;
        }
        public static bool operator != ( RecordVal left, decimal right )
        {
            if ( left.dataType != FormRecordDataType.Number )
            {
                return true;
            }
            return Convert.ToDecimal(left.value) != right;
        }
        public static bool operator == ( decimal left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.Number )
            {
                return false;
            }
            return Convert.ToDecimal(right.value) == left;
        }
        public static bool operator != ( decimal left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.Number )
            {
                return true;
            }
            return Convert.ToDecimal(right.value) != left;
        }

        public static bool operator >= ( decimal left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left >= Convert.ToDecimal(right.value);
        }
        public static bool operator <= ( decimal left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left <= Convert.ToDecimal(right.value);
        }
        public static bool operator > ( decimal left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left > Convert.ToDecimal(right.value);
        }
        public static bool operator < ( decimal left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left < Convert.ToDecimal(right.value);
        }

        public static bool operator >= ( RecordVal left, decimal right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToDecimal(left.value) >= right;
        }
        public static bool operator > ( RecordVal left, decimal right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToDecimal(left.value) > right;
        }

        public static bool operator <= ( RecordVal left, decimal right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToDecimal(left.value) <= right;
        }
        public static bool operator < ( RecordVal left, decimal right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToDecimal(left.value) < right;
        }

        #endregion

        #region string
        public static bool operator == ( RecordVal left, string right )
        {
            if ( left.dataType != FormRecordDataType.String )
            {
                return false;
            }
            return Convert.ToString(left.value) == right;
        }
        public static bool operator != ( RecordVal left, string right )
        {
            if ( left.dataType != FormRecordDataType.String )
            {
                return true;
            }
            return Convert.ToString(left.value) != right;
        }
        public static bool operator == ( string left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.String )
            {
                return false;
            }
            return Convert.ToString(right.value) == left;
        }
        public static bool operator != ( string left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.String )
            {
                return true;
            }
            return Convert.ToString(right.value) != left;
        }
        public static bool operator >= ( string left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val >= Convert.ToDecimal(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                right.dataType == FormRecordDataType.Date ||
                right.dataType == FormRecordDataType.DateTime ||
                right.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(left, out long val) )
                {
                    return val >= Convert.ToInt64(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val >= Convert.ToDecimal(right.value);
                }
                return false;
            }
            return false;
        }
        public static bool operator <= ( string left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val <= Convert.ToDecimal(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                right.dataType == FormRecordDataType.Date ||
                right.dataType == FormRecordDataType.DateTime ||
                right.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(left, out long val) )
                {
                    return val <= Convert.ToInt64(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val <= Convert.ToDecimal(right.value);
                }
                return false;
            }
            return false;
        }
        public static bool operator > ( string left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val > Convert.ToDecimal(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                right.dataType == FormRecordDataType.Date ||
                right.dataType == FormRecordDataType.DateTime ||
                right.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(left, out long val) )
                {
                    return val > Convert.ToInt64(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val > Convert.ToDecimal(right.value);
                }
                return false;
            }
            return false;
        }
        public static bool operator < ( string left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val < Convert.ToDecimal(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long ||
                right.dataType == FormRecordDataType.Date ||
                right.dataType == FormRecordDataType.DateTime ||
                right.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(left, out long val) )
                {
                    return val < Convert.ToInt64(right.value);
                }
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(left, out decimal val) )
                {
                    return val < Convert.ToDecimal(right.value);
                }
                return false;
            }
            return false;
        }


        public static bool operator >= ( RecordVal left, string right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToDecimal(left.value) >= val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long ||
                left.dataType == FormRecordDataType.Date ||
                left.dataType == FormRecordDataType.DateTime ||
                left.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(right, out long val) )
                {
                    return Convert.ToInt64(left.value) >= val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToInt64(left.value) >= val;
                }
                return false;
            }
            return false;
        }
        public static bool operator > ( RecordVal left, string right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToDecimal(left.value) > val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long ||
                left.dataType == FormRecordDataType.Date ||
                left.dataType == FormRecordDataType.DateTime ||
                left.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(right, out long val) )
                {
                    return Convert.ToInt64(left.value) > val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToInt64(left.value) > val;
                }
                return false;
            }
            return false;
        }

        public static bool operator <= ( RecordVal left, string right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToDecimal(left.value) <= val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long ||
                left.dataType == FormRecordDataType.Date ||
                left.dataType == FormRecordDataType.DateTime ||
                left.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(right, out long val) )
                {
                    return Convert.ToInt64(left.value) <= val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToInt64(left.value) <= val;
                }
                return false;
            }
            return false;
        }
        public static bool operator < ( RecordVal left, string right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToDecimal(left.value) < val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long ||
                left.dataType == FormRecordDataType.Date ||
                left.dataType == FormRecordDataType.DateTime ||
                left.dataType == FormRecordDataType.Time )
            {
                if ( long.TryParse(right, out long val) )
                {
                    return Convert.ToInt64(left.value) < val;
                }
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Number )
            {
                if ( decimal.TryParse(right, out decimal val) )
                {
                    return Convert.ToInt64(left.value) < val;
                }
                return false;
            }
            return false;
        }
        #endregion

        #region long

        public static bool operator >= ( long left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left >= Convert.ToInt64(right.value);
        }
        public static bool operator <= ( long left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left <= Convert.ToInt64(right.value);
        }
        public static bool operator > ( long left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left > Convert.ToInt64(right.value);
        }
        public static bool operator < ( long left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return left < Convert.ToInt64(right.value);
        }

        public static bool operator >= ( RecordVal left, long right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToInt64(left.value) >= right;
        }
        public static bool operator > ( RecordVal left, long right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToInt64(left.value) > right;
        }

        public static bool operator <= ( RecordVal left, long right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToInt64(left.value) <= right;
        }
        public static bool operator < ( RecordVal left, long right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool )
            {
                return false;
            }
            return Convert.ToInt64(left.value) < right;
        }
        public static bool operator == ( RecordVal left, long right )
        {
            if ( left.dataType != FormRecordDataType.Long ||
                left.dataType != FormRecordDataType.Date ||
                left.dataType != FormRecordDataType.DateTime ||
                left.dataType != FormRecordDataType.Time )
            {
                return false;
            }
            return Convert.ToInt64(left.value) == right;
        }
        public static bool operator != ( RecordVal left, long right )
        {
            if ( left.dataType != FormRecordDataType.Long ||
                left.dataType != FormRecordDataType.Date ||
                left.dataType != FormRecordDataType.DateTime ||
                left.dataType != FormRecordDataType.Time )
            {
                return true;
            }
            return Convert.ToInt64(left.value) != right;
        }
        public static bool operator == ( long left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.Long ||
                right.dataType != FormRecordDataType.Date ||
                right.dataType != FormRecordDataType.DateTime ||
                right.dataType != FormRecordDataType.Time )
            {
                return false;
            }
            return Convert.ToInt64(right.value) == left;
        }
        public static bool operator != ( long left, RecordVal right )
        {
            if ( right.dataType != FormRecordDataType.Long ||
                right.dataType != FormRecordDataType.Date ||
                right.dataType != FormRecordDataType.DateTime ||
                right.dataType != FormRecordDataType.Time )
            {
                return true;
            }
            return Convert.ToInt64(right.value) != left;
        }

        #endregion


        #region object
        public static bool operator >= ( object left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool || left == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long
                || right.dataType == FormRecordDataType.Date
                || right.dataType == FormRecordDataType.DateTime
                || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) >= Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left) >= Convert.ToDecimal(right.value);
        }
        public static bool operator <= ( object left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool || left == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long
                || right.dataType == FormRecordDataType.Date
                || right.dataType == FormRecordDataType.DateTime
                || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) <= Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left) <= Convert.ToDecimal(right.value);
        }
        public static bool operator < ( object left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool || left == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long
                || right.dataType == FormRecordDataType.Date
                || right.dataType == FormRecordDataType.DateTime
                || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) < Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left) < Convert.ToDecimal(right.value);
        }
        public static bool operator > ( object left, RecordVal right )
        {
            if ( right.value == null || right.dataType == FormRecordDataType.Bool || left == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.Long
                || right.dataType == FormRecordDataType.Date
                || right.dataType == FormRecordDataType.DateTime
                || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) > Convert.ToInt64(right.value);
            }
            return Convert.ToDecimal(left) > Convert.ToDecimal(right.value);
        }

        public static bool operator >= ( RecordVal left, object right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool || right == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long
                || left.dataType == FormRecordDataType.Date
                || left.dataType == FormRecordDataType.DateTime
                || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) >= Convert.ToInt64(right);
            }
            return Convert.ToDecimal(left.value) >= Convert.ToDecimal(right);
        }
        public static bool operator <= ( RecordVal left, object right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool || right == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long
                || left.dataType == FormRecordDataType.Date
                || left.dataType == FormRecordDataType.DateTime
                || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) <= Convert.ToInt64(right);
            }
            return Convert.ToDecimal(left.value) <= Convert.ToDecimal(right);
        }

        public static bool operator > ( RecordVal left, object right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool || right == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long
                || left.dataType == FormRecordDataType.Date
                || left.dataType == FormRecordDataType.DateTime
                || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) > Convert.ToInt64(right);
            }
            return Convert.ToDecimal(left.value) > Convert.ToDecimal(right);
        }
        public static bool operator < ( RecordVal left, object right )
        {
            if ( left.value == null || left.dataType == FormRecordDataType.Bool || right == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.Long
                || left.dataType == FormRecordDataType.Date
                || left.dataType == FormRecordDataType.DateTime
                || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) < Convert.ToInt64(right);
            }
            return Convert.ToDecimal(left.value) < Convert.ToDecimal(right);
        }
        public static bool operator == ( RecordVal left, object right )
        {
            if ( left.value == right )
            {
                return true;
            }
            else if ( left.value == null || right == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left.value) == Convert.ToString(right);
            }
            else if ( left.dataType == FormRecordDataType.Long || left.dataType == FormRecordDataType.Date || left.dataType == FormRecordDataType.DateTime || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) == Convert.ToInt64(right);
            }
            else if ( left.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left.value) == Convert.ToBoolean(right);
            }
            else
            {
                return Convert.ToDecimal(left.value) == Convert.ToDecimal(right);
            }
        }
        public static bool operator != ( RecordVal left, object right )
        {
            if ( left.value == right )
            {
                return false;
            }
            else if ( left.value == null || right == null )
            {
                return true;
            }
            else if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left.value) != Convert.ToString(right);
            }
            else if ( left.dataType == FormRecordDataType.Long || left.dataType == FormRecordDataType.Date || left.dataType == FormRecordDataType.DateTime || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) != Convert.ToInt64(right);
            }
            else if ( left.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left.value) != Convert.ToBoolean(right);
            }
            else
            {
                return Convert.ToDecimal(left.value) != Convert.ToDecimal(right);
            }
        }

        public static bool operator == ( object left, RecordVal right )
        {
            if ( left == right.value )
            {
                return true;
            }
            else if ( left == null || right.value == null )
            {
                return false;
            }
            else if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left) == Convert.ToString(right.value);
            }
            else if ( right.dataType == FormRecordDataType.Long || right.dataType == FormRecordDataType.Date || right.dataType == FormRecordDataType.DateTime || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) == Convert.ToInt64(right.value);
            }
            else if ( right.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left) == Convert.ToBoolean(right.value);
            }
            else
            {
                return Convert.ToDecimal(left) == Convert.ToDecimal(right.value);
            }
        }
        public static bool operator != ( object left, RecordVal right )
        {
            if ( left == right.value )
            {
                return false;
            }
            else if ( left == null || right.value == null )
            {
                return true;
            }
            else if ( right.dataType == FormRecordDataType.String || right.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left) != Convert.ToString(right.value);
            }
            else if ( right.dataType == FormRecordDataType.Long || right.dataType == FormRecordDataType.Date || right.dataType == FormRecordDataType.DateTime || right.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left) != Convert.ToInt64(right.value);
            }
            else if ( right.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left) != Convert.ToBoolean(right.value);
            }
            else
            {
                return Convert.ToDecimal(left) != Convert.ToDecimal(right.value);
            }
        }
        #endregion


        public static bool operator == ( RecordVal left, RecordVal right )
        {
            if ( left.value == right.value )
            {
                return true;
            }
            else if ( left.value == null || right.value == null )
            {
                return false;
            }
            else if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left.value) == Convert.ToString(right.value);
            }
            else if ( left.dataType == FormRecordDataType.Long || left.dataType == FormRecordDataType.Date || left.dataType == FormRecordDataType.DateTime || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) == Convert.ToInt64(right.value);
            }
            else if ( left.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left.value) == Convert.ToBoolean(right.value);
            }
            else
            {
                return Convert.ToDecimal(left.value) == Convert.ToDecimal(right.value);
            }
        }
        public static bool operator != ( RecordVal left, RecordVal right )
        {
            if ( left.value == right.value )
            {
                return false;
            }
            else if ( left.value == null || right.value == null )
            {
                return true;
            }
            else if ( left.dataType == FormRecordDataType.String || left.dataType == FormRecordDataType.Array )
            {
                return Convert.ToString(left.value) != Convert.ToString(right.value);
            }
            else if ( left.dataType == FormRecordDataType.Long || left.dataType == FormRecordDataType.Date || left.dataType == FormRecordDataType.DateTime || left.dataType == FormRecordDataType.Time )
            {
                return Convert.ToInt64(left.value) != Convert.ToInt64(right.value);
            }
            else if ( left.dataType == FormRecordDataType.Bool )
            {
                return Convert.ToBoolean(left.value) != Convert.ToBoolean(right.value);
            }
            else
            {
                return Convert.ToDecimal(left.value) != Convert.ToDecimal(right.value);
            }
        }

        public static explicit operator double ( RecordVal val )
        {
            return decimal.ToDouble(Convert.ToDecimal(val.value));
        }

        public static explicit operator decimal ( RecordVal val )
        {
            return Convert.ToDecimal(val.value);
        }

        public static explicit operator int ( RecordVal val )
        {
            return Convert.ToInt32(val.value);
        }

        public static explicit operator long ( RecordVal val )
        {
            return Convert.ToInt64(val.value);
        }

        public static explicit operator DateTime ( RecordVal val )
        {
            if ( val.dataType == FormRecordDataType.Date || val.dataType == FormRecordDataType.DateTime )
            {
                return Convert.ToInt64(val.value).ToDateTime();
            }
            throw new ErrorException("form.data.format.error");
        }

        public static explicit operator string ( RecordVal val )
        {
            if ( val.value == null )
            {
                return null;
            }
            return Convert.ToString(val.value);
        }
    }
}
